Repository navigation
Conversation
|
@github-actions crossbow submit -g cpp |
|
Revision: 7240ca253191e6309e8335d0c190100f193bd4fe Submitted crossbow builds: ursacomputing/crossbow @ actions-906afe6414 |
|
@github-actions crossbow submit test-ubuntu-22.04-cpp-emscripten |
|
Revision: 98b46082009932b78e1c715cc8f96417408bf5ea Submitted crossbow builds: ursacomputing/crossbow @ actions-bb75d4faa6
|
|
@github-actions crossbow submit -g cpp |
|
Revision: b46eb0b292eaa9e27e1c04ceaf9b4a26603db1c6 Submitted crossbow builds: ursacomputing/crossbow @ actions-c444380c6c |
|
@kou @pitrou this is still far from ready but all the C++ jobs are currently successful with this initial PoC. The only failure is the |
There was a problem hiding this comment.
Could you add #pragma once?
| #include "arrow/compute/registry.h" | |
| #pragma once | |
| #include "arrow/compute/registry.h" |
There was a problem hiding this comment.
I've moved this to kernels/api.h where I've added #pragma once shouldn't be necessary here now
#45618 (comment) is the answer of this. |
This all seems very complicated to me. You should only need something like: namespace {
bool RegisterComputeKernels() {
auto registry = GetFunctionRegistry();
internal::RegisterScalarArithmetic(registry);
// etc.
return true; // dummy return value, must return something
}
bool g_kernels_registered = RegisterComputeKernels();
}(various spellings of this are possible, but the semantics would be the same) |
I also thought that should work but, if I understand correctly, this diff should do the trick: diff --git a/cpp/src/arrow/compute/kernels/api.h b/cpp/src/arrow/compute/kernels/api.h
index 3385d4cc80..8a22c6c3ca 100644
--- a/cpp/src/arrow/compute/kernels/api.h
+++ b/cpp/src/arrow/compute/kernels/api.h
@@ -25,5 +25,3 @@
/// @}
#include "arrow/compute/kernels/registry.h" // IWYU pragma: export
-
-static arrow::Status g_kernels_registered = arrow::compute::RegisterComputeKernels();
diff --git a/cpp/src/arrow/compute/kernels/registry.cc b/cpp/src/arrow/compute/kernels/registry.cc
index fe9c2df724..d9c899bec4 100644
--- a/cpp/src/arrow/compute/kernels/registry.cc
+++ b/cpp/src/arrow/compute/kernels/registry.cc
@@ -33,11 +33,11 @@
namespace arrow {
namespace compute {
-Status RegisterComputeKernels() {
+bool RegisterComputeKernels() {
auto registry = GetFunctionRegistry();
// TODO: Do we have a different way to avoid double registration?
if (registry->GetFunction("abs").ok()) {
- return Status::OK();
+ return true;
}
// Register additional kernels on libarrow_compute
// Scalar functions
@@ -78,7 +78,9 @@ Status RegisterComputeKernels() {
internal::RegisterScalarAggregateTDigest(registry);
internal::RegisterScalarAggregateVariance(registry);
- return Status::OK();
+ return true;
}
+
+static bool g_kernels_registered = RegisterComputeKernels();
} // namespace compute
} // namespace arrow
diff --git a/cpp/src/arrow/compute/kernels/registry.h b/cpp/src/arrow/compute/kernels/registry.h
index 02c002126a..075bd92002 100644
--- a/cpp/src/arrow/compute/kernels/registry.h
+++ b/cpp/src/arrow/compute/kernels/registry.h
@@ -19,10 +19,9 @@
#include "arrow/compute/registry.h"
#include "arrow/compute/visibility.h"
-#include "arrow/status.h"
namespace arrow::compute {
-ARROW_COMPUTE_EXPORT Status RegisterComputeKernels();
+ARROW_COMPUTE_EXPORT bool RegisterComputeKernels();
} // namespace arrow::computebut on this case, the kernels are not registered when linking edit: added static to the variable (same output) |
|
Well, is |
|
What do you mean? We are linking it and we have the tests including the headers for |
299bb4a to
7793eff
Compare
|
It seems that we need This is not a good code but this works on Debian GNU/Linux with g++ 14.2.0: diff --git a/cpp/src/arrow/compute/kernels/CMakeLists.txt b/cpp/src/arrow/compute/kernels/CMakeLists.txt
index 3e5239be96..d79482e629 100644
--- a/cpp/src/arrow/compute/kernels/CMakeLists.txt
+++ b/cpp/src/arrow/compute/kernels/CMakeLists.txt
@@ -151,6 +151,9 @@ add_arrow_compute_test(aggregate_test
SOURCES
aggregate_test.cc
EXTRA_LINK_LIBS
+ "-Wl,--push-state,--no-as-needed"
+ arrow_compute_shared
+ "-Wl,--pop-state"
arrow_compute_kernels_testing
arrow_compute_testing
Boost::headers)
diff --git a/cpp/src/arrow/compute/kernels/api.h b/cpp/src/arrow/compute/kernels/api.h
index 3385d4cc80..deaf82626f 100644
--- a/cpp/src/arrow/compute/kernels/api.h
+++ b/cpp/src/arrow/compute/kernels/api.h
@@ -23,7 +23,3 @@
/// \defgroup compute-kernels Extra compute kernels
/// @{
/// @}
-
-#include "arrow/compute/kernels/registry.h" // IWYU pragma: export
-
-static arrow::Status g_kernels_registered = arrow::compute::RegisterComputeKernels();
diff --git a/cpp/src/arrow/compute/kernels/registry.cc b/cpp/src/arrow/compute/kernels/registry.cc
index fe9c2df724..d62d25f74f 100644
--- a/cpp/src/arrow/compute/kernels/registry.cc
+++ b/cpp/src/arrow/compute/kernels/registry.cc
@@ -33,11 +33,11 @@
namespace arrow {
namespace compute {
-Status RegisterComputeKernels() {
+void RegisterComputeKernels() {
auto registry = GetFunctionRegistry();
// TODO: Do we have a different way to avoid double registration?
if (registry->GetFunction("abs").ok()) {
- return Status::OK();
+ return;
}
// Register additional kernels on libarrow_compute
// Scalar functions
@@ -77,8 +77,10 @@ Status RegisterComputeKernels() {
internal::RegisterScalarAggregateQuantile(registry);
internal::RegisterScalarAggregateTDigest(registry);
internal::RegisterScalarAggregateVariance(registry);
-
- return Status::OK();
}
+
+RegistryInitializer::RegistryInitializer() { RegisterComputeKernels(); }
+
+RegistryInitializer RegistryInitializer::instance;
} // namespace compute
} // namespace arrow
diff --git a/cpp/src/arrow/compute/kernels/registry.h b/cpp/src/arrow/compute/kernels/registry.h
index 02c002126a..2d9d95240e 100644
--- a/cpp/src/arrow/compute/kernels/registry.h
+++ b/cpp/src/arrow/compute/kernels/registry.h
@@ -23,6 +23,11 @@
namespace arrow::compute {
-ARROW_COMPUTE_EXPORT Status RegisterComputeKernels();
+ARROW_COMPUTE_EXPORT void RegisterComputeKernels();
+class ARROW_COMPUTE_EXPORT RegistryInitializer {
+ public:
+ RegistryInitializer();
+ static RegistryInitializer instance;
+};
} // namespace arrow::compute |
There was a problem hiding this comment.
I haven't been able to make this work for WIN32 yet, I'll keep investigating how to force the linker to not optimize out arrow_compute_shared and force adding it on WIN32. I am unsure this is what we want to do. From what I understand the linker is allowed to skip libraries not used by the end result and as libarrow_compute_shared is never used its optimized out, that's why we have to use the --no-as-needed / -force-load / while-archive flags. From my understanding, having the static initializer there and never calling anything explicitly on libarrow_compute will make anyone that tries to use Compute and link against Arrow to require those flags to be set making the use of arrow_compute quite cumbersome.
At this point I think the explicit function call to RegisterComputeKernels is a better approach as it's much simpler from a user stand-point.
@kou @pitrou any thoughts on this?
I am trying to investigate as this is new for me :) and I haven't found much info about those flags or how to use them on the different platforms. A couple of links issues around those (not super relevant):
https://discourse.cmake.org/t/add-linker-archive-options-before-and-after-a-target/2373
https://github.com/PixarAnimationStudios/OpenUSD/pull/2284/files
There was a problem hiding this comment.
At this point I think the explicit function call to
RegisterComputeKernelsis a better approach as it's much simpler from a user stand-point.
Well, that's a good point. I wasn't aware that using a static initializer would have such pitfalls.
…red library Fix build for some benchmarks and examples Only link arrow_compute to benchmark if we are building benchmarks Rename arrow_compute target to arrow_compute_core Try fixing arrow_compute_core target for Windows Remove ARROW_EXPORT from arrow_compute in order to fix inconsistent linkage on Windows Remove ARROW_EXPORT from arrow_compute in order to fix inconsistent linkage on Windows 2 Remove ARROW_EXPORT from arrow_compute in order to fix inconsistent linkage on Windows 3 Link arrow_compute with libarrow Some code reorganization and add ARROW_EXPORT to required function Add duplicated codegen_internal to arrow_compute Remove some more ARROW_EXPORT (this will have to be reverted) Add ArrowCompute dependency to ArrowAcery and interface libs Define ARROW_COMPUTE_EXPORT and add it to some of the deleted ARROW_EXPORT. Fix a typo too Fix wrongly added ARROW_EXPORT for ARROW_COMPUTE_EXPORT Add some more missing ARROW_COMPUTE_EXPORT Export symbols for kernel registration and move outside of internal namespace Move problematic function to compute/codegen_internal instead of compute/kernels/codegen_internal Add ARROW_EXPORT ot FirstType Remove duplicated symbol, expose new required symbols Add missing header Fix linked libs for arrow_compute Failed attempt to fix tutorial examples Fix meson build Fix correctly installing headers for kernels Register Compute Kernels for pyarrow when importing pyarrow.compute Fix visibility.h and correct api Add registration of kernels to R to get tests passing Fix wrong rebase
… RegisterComputeKernels Fix python build and tests Fix lint, ruby and some example tests Try fixing R Windows build Try adding arrow_compute as dependency for Apache Arrow GLib Revert "Try adding arrow_compute as dependency for Apache Arrow GLib" This reverts commit 40e818aa4ffc6f161fd18f64aff4f5deffca3fc4. Stop using arrow/compute/kernels/test_util_internal.h and use arrow/compute/kernels/api.h on tests instead Add correct pkg-config flags for static builds Add missing flags on configure_dev on configure.win for R Windows
…o-as-needed linker flags Try adding --whole-archive instead of --no-as-needed for MinGW More linker flags Try removing Windows flags Try adding /WHOLEARCHIVE LINK_FLAGS on MSVC Try using target_link_options instead of set_property LINK_FLAGS for MSVC and try WIN32 not MSVC flags Try using generator expression to retrieve filename for arrow_compute_shared for /WHOLEARCHIVE flag Add missing multi value arg for function Add cmake_verbose logs Maybe if I pass the flags they are added :) Remove leading whitespace Revert back now that the flags are being passed Add EXTRA_LINK_OPTIONS to function definition arrow_compute_shared.lib does not exist, try arrow_compute.lib What about a combination? Trigger pre-commit
|
I am going to open a new PR dropping the last two commits and going back to the manual registration. We won't have to do this for the different bindings as they can register the kernels automatically but this will have to be done by users of Arrow compute. |
|
Closing this PR as this was already merged using a different approach. |
This is just a draft investigating some possible approaches.
Rationale for this change
TBD
What changes are included in this PR?
TBD
Are these changes tested?
Yes on CI.
Are there any user-facing changes?
TODO: Expand once the approach is clearer
Yes.
This PR includes breaking changes to public APIs.